<template>
  <div
    class="product-one-col-wrap j_akc_ubt"
    :class="{ vertical: isVerticalNav }"
    @click="goProductDetail"
  >
    <div class="img-wrap-box" :class="{ vertical: isVerticalNav }">
      <img v-lazy="imgUrl" :class="{ vertical: isVerticalNav }" />
      <!-- [省赚] 组件 -->
      <profit
        v-if="isShowProfit"
        class="profit--private"
        :class="{ vertical: isVerticalNav }"
        :profitObj="product"
        :isVerticalNav="isVerticalNav"
      ></profit>
      <div v-if="product.sellOut" class="sellout">
        售罄
      </div>
      <!-- 打标 -->
      <img
        v-if="product.productSubscriptUrl"
        class="mark-img"
        :src="product.productSubscriptUrl"
      />
    </div>
    <div class="product-info-right">
      <p class="product-des more_text">
        {{ product.productName || '' }}
      </p>
      <div class="footer-wrap" :class="{ vertical: isVerticalNav }">
        <div class="price">
          <span class="unit">¥</span><span>{{ product.price }}</span
          ><span v-if="!isVerticalNav" class="linePrice"
            >¥{{ product.tagPrice }}</span
          >
        </div>
        <div v-if="product.sellOut" class="buy-btn buy-over">
          已抢光
        </div>
        <div
          v-if="seckillStatus == 2 && !product.sellOut"
          class="buy-btn buy-over"
        >
          已结束
        </div>
        <div
          v-if="seckillStatus == 0 && !product.sellOut"
          class="buy-btn buy-over"
        >
          即将开始
        </div>
        <div
          v-if="seckillStatus == 1 && !product.sellOut"
          class="buy-btn"
          @click.stop="handleBtnClick"
        >
          <i class="icon-buy" :class="{ 'icon-share': isUserOfB }"></i
          ><span>{{ isUserOfB ? '转发' : '去抢购' }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { formatImgUrl, http2https } from '@/utils/util';
import profit from '@/components/profit.vue'; // [省赚] 组件

export default {
  name: 'productOneCol',
  components: {
    profit
  },
  props: {
    product: {
      type: Object,
      default: () => {}
    },
    index: {
      type: Number,
      default: 0
    },
    isVerticalNav: {
      type: Boolean,
      default: false
    },
    seckillStatus: {
      type: Number,
      default: 1
    }
  },
  computed: {
    imgUrl() {
      let { productPicUrl } = this.product || {};
      if (productPicUrl) {
        productPicUrl = formatImgUrl(productPicUrl.split(',')[0], 112, 112);
        return http2https(productPicUrl);
      }
      return null;
    },
    isUserOfB() {
      return true;
    },
    isShowProfit() {
      return this.isUserOfB && this.product.profit;
    }
  },
  methods: {
    // 前往商品详情页
    goProductDetail() {
      this.$emit('goProductDetail');
    },
    handleBtnClick() {
      if (this.isUserOfB) {
        this.$emit('shareProduct');
      } else {
        this.$emit('addToCart');
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.product-one-col-wrap {
  width: 355px;
  padding: 14px;
  box-sizing: border-box;
  background-color: #fff;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
  display: flex;
  &.vertical {
    width: 307px;
  }

  .img-wrap-box {
    position: relative;
    width: 112px;
    height: 112px;
    &.vertical {
      width: 96px;
      height: 96px;
    }
    img {
      width: 112px;
      height: 112px;
      object-fit: cover;
      border-radius: 6px;
      display: block;
      &.vertical {
        width: 96px;
        height: 96px;
      }
    }
    .profit--private {
      max-width: 112px;
      &.vertical {
        max-width: 96px;
      }
    }
    .mark-img {
      position: absolute;
      top: 0;
      right: 5px;
      width: 19px;
      height: 21px;
      object-fit: cover;
      display: block;
      border-radius: 0;
    }
    .extra-profit {
      width: 30px;
      height: 18px;
      padding-left: 22px;
      margin-left: -20px;
      padding-right: 2px;
      background: linear-gradient(
        155deg,
        rgba(255, 0, 141, 1) 0%,
        rgba(255, 0, 34, 1) 100%
      );
      border-radius: 9px 9px 9px 0;
      font-size: 10px;
      line-height: 18px;
      color: #fff;
      z-index: 1;
      text-overflow: ellipsis;
      overflow: hidden;
      word-break: break-all;
      white-space: nowrap;
    }
    .sellout {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      margin: auto;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 44px;
      height: 44px;
      border-radius: 50%;
      color: #fff;
      font-size: 12px;
      background-color: rgba(0, 0, 0, 0.6);
    }
  }

  .product-info-right {
    margin-left: 12px;
    height: 96px;
    flex: 1;
    .product-des {
      width: 100%;
      font-size: 14px;
      font-weight: 500;
      color: #333;
    }
    .footer-wrap {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 44px;
      &.vertical {
        margin-top: 28px;
      }
    }
    .price {
      font-size: 20px;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
      color: #fe1e3d;
      line-height: 20px;
      /*display: flex;*/
      /*align-items: flex-end;*/
    }
    .unit {
      font-size: 12px;
      margin-right: 2px;
      color: #fe1e3d;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
    }

    .linePrice {
      text-decoration: line-through;
      font-size: 12px;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
      color: #999;
      line-height: 14px;
      margin-left: 4px;
    }
    .buy-btn {
      width: 84px;
      height: 28px;
      background: #ff1010;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #fff;
      font-size: 14px;
      font-weight: 600;
      border-radius: 14px;
      line-height: normal;
      img {
        width: 16px;
        height: 16px;
        object-fit: cover;
      }
    }
    .reminded {
      background: rgba(255, 16, 16, 0.4);
      width: 96px;
      font-size: 14px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: rgba(255, 255, 255, 1);
    }
    .icon-buy {
      width: 8px;
      height: 14px;
      background: url('../../../assets/superBrand/icon-buy.png') no-repeat;
      background-size: 100% 100%;
    }
    .icon-share {
      width: 20px;
      height: 20px;
      margin-right: 5px;
      margin-top: -1px;
      background: url('../../../assets/zhuanfa_white_icon.png') no-repeat;
      background-size: 100% 100%;
    }
    .buy-over {
      opacity: 0.4;
    }
  }
  .more_text {
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-all;
    height: 40px;
    line-height: 20px;
    overflow-y: hidden;
  }
}
</style>
